<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div class="parent">
    <div class="child">Hello world!</div>
  </div>

  <button>insertBefore</button>

  <script>
    const parent = document.querySelector('.parent')
    const child = document.querySelector('.child')

    function onClick() {
      const node = document.createElement('p')
      node.innerHTML = new Date().toString()
      // 在元素的指定子节点之前添加
      parent.insertBefore(node, child)
    }

    document.querySelector('button').addEventListener('click', onClick)
  </script>
</body>

</html>